AI Lessons
Lesson 14: Training an audio classifier

Purpose: How a model is taught to tell one sound from another by choosing the classes, recording the samples and training on them, and how the samples chosen decide what the model gets right.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connections / Wi-Fi.

A working microphone on every machine, and headphones or speakers.

Prior knowledge
  • Browsers
  • Sound stored as digital data
  • AI learns from labelled examples
Exercises

Exercise



  • Create and train an audio classification model in Teachable Machine to recognise different sounds.
  • Click here to open Teachable Machine and start an audio project.
  • Test the model by making the sounds you trained it on and see if it recognises them correctly. Try making a sound that you did not train it on and see how it responds.
  • Download the model and open the files that are generated.
    1. You will find a file called "model.json" in the folder. Open it in a text editor and look for the "labels" section. This will show you the classes that your model has been trained to recognise.
    2. You can also open the "metadata.json" file to see information about the model, such as the number of training samples and the accuracy of the model.
    3. Open the "weights.bin" file in a binary editor to see the actual weights of the model. This file contains the learned parameters of the model that allow it to make predictions based on the input data.

Solutions



Teacher's Instruction:
  1. Check that the microphone works before the class. Teachable Machine records straight from the browser, so it will ask for permission to use the microphone the first time.
  2. Explain the following to students:
    • Teachable Machine always needs a background noise class as well as the sounds to be recognised. Without it the model has no way to say “none of these”, so it must pick one of the sounds even when nothing is happening. This is important to demonstrate to the students. So train a model where there is no background noise class and observe how the classification happens.
    • Guide the students in choosing sounds that are clearly different from one another - a clap, a whistle and a knock work better than three ways of saying the same word.
    • Keep the number of samples roughly equal across the classes. If one class has far more, the model leans towards it, which is the bias idea from the earlier lessons appearing in the students’ own work.
    • Once trained, read the confidence score with the class, not just the label. Ask what a prediction of 60 per cent should mean for how much they trust it.
    • Test the model with a sound it was never trained on and let the students watch the model answer confidently and wrongly.
    • Try the model again with the classroom noisier than it was during recording. A model trained in quiet conditions performs worse in noisy ones, which is a limitation of the samples rather than a fault in the code.
  3. Points to Ponder:
    • When you opened the downloaded model file, did it contain any audio samples? The weights.bin contains only numbers. How will the model classify using those numbers?